package org.tbjd.client.customWidgets;

import java.util.List;

import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Widget;

public class HideableWidgetsPanel extends AbsolutePanel {

	private List<Widget> widgets = null;

	public HideableWidgetsPanel() {
		super();
		sinkEvents(Event.ONMOUSEOVER);
		sinkEvents(Event.ONMOUSEOUT);
	}

	public void setHideableWidgets(List<Widget> widgetsToHide) {
		this.widgets  = widgetsToHide;
		hideWidgets();
	}	

	public void onBrowserEvent(Event event) {
		super.onBrowserEvent(event);

		switch (event.getTypeInt()) {
		case Event.ONMOUSEOVER:
			showWidgets();
			break;

		case Event.ONMOUSEOUT:
			hideWidgets();
			break;
		}
	}

	private void showWidgets() {
		for (Widget eachWidget : this.widgets) {
			eachWidget.setVisible(true);
		}
	}

	private void hideWidgets() {
		for (Widget eachWidget : this.widgets) {
			eachWidget.setVisible(false);
		}
	}

}
